package com.ipfsemc.ipfsemc.controller.v1;

import com.ipfsemc.ipfsemc.model.UserInfo;
import com.ipfsemc.ipfsemc.model.Withdraw;
import com.ipfsemc.ipfsemc.service.IUserInfoService;
import com.ipfsemc.ipfsemc.service.IWithdrawService;
import com.ipfsemc.ipfsemc.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RequestMapping("withdraw")
@RestController
@Api(value = "WithdrawController", tags = "提现")

public class WithdrawController {

//    private static final Logger logger = LoggerFactory.getLogger(WithdrawController.class);
//
//    @Autowired
//    private IWithdrawService withdrawService;
//
//    @Autowired
//    private IUserInfoService userInfoService;
//
//    @ApiOperation(value = "",httpMethod = "POST")
//    @RequestMapping(value = "addWithdraw",method = RequestMethod.POST)
//    public JsonData addWithdraw(@RequestBody Withdraw withdraw){
//        JsonData jsonData=new JsonData();
//        try {
//            if(null==withdraw.getUserId()||withdraw.getUserId().equals("")){
//                jsonData.setMessage("参数异常！");
//            }else{
//
//
//                BigDecimal b = new BigDecimal(0.05);
//                withdraw.setWithdrawCharge(b);
//                withdraw.setWithdrawReality(withdraw.getWithdrawApply().subtract(withdraw.getWithdrawApply().multiply(b)));
//
//                UserInfo userInfo = userInfoService.selectOne(withdraw.getUserId());
//
//
//                //余额不为空  并且余额大于支付价格
//                if (null != userInfo.getBalance() && userInfo.getBalance().compareTo(withdraw.getWithdrawReality()) != -1) {
//
//                    withdrawService.add(withdraw);
//                    jsonData.setCode(0);
//                    jsonData.setMessage("提现申请成功！");
//                }else {
//                    jsonData.setMessage("你的提现金额不足！");
//                }
//            }
//        }catch (Exception e){
//
//                logger.error("[withdraw][addWithdraw]", e);
//                jsonData.setMessage("系统错误,请稍后重试");
//        }
//
//        return jsonData;
//    }
//
//    @ApiOperation(value = "",httpMethod = "POST")
//    @RequestMapping(value = "updateWithdraw",method = RequestMethod.POST)
//    public JsonData updateWithdraw(@RequestBody Withdraw withdraw){
//        JsonData jsonData=new JsonData();
//        try {
//            if(null==withdraw.getUserId()||withdraw.getUserId().equals("")){
//                jsonData.setMessage("参数异常！");
//            }else{
//
//                int update = withdrawService.update(withdraw);
//                if(update<0){
//                    jsonData.setCode(0);
//                    jsonData.setMessage("操作成功！！");
//                }
//
//            }
//        }catch (Exception e){
//
//            logger.error("[withdraw][updateWithdraw]", e);
//            jsonData.setMessage("系统错误,请稍后重试");
//        }
//
//        return jsonData;
//    }
//
//    @ApiOperation(value = "",httpMethod = "POST")
//    @RequestMapping(value = "listByUser",method = RequestMethod.GET)
//    public JsonData listByUser(Withdraw withdraw){
//        JsonData jsonData=new JsonData();
//        try {
//            if(null==withdraw.getUserId()||withdraw.getUserId().equals("")){
//                jsonData.setMessage("参数异常！");
//            }else{
//                List<Withdraw> withdraws = withdrawService.listByUser(withdraw);
//                jsonData.setResult(withdraws);
//                jsonData.setCode(0);
//            }
//        }catch (Exception e){
//
//            logger.error("[withdraw][listByUser]", e);
//            jsonData.setMessage("系统错误,请稍后重试");
//        }
//
//        return jsonData;
//    }
}
